//
//  YSMarkBottomBar.m
//  Yueshi
//
//  Created by Northwan on 15/8/31.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSMarkBottomBar.h"

@interface YSMarkBottomBar()

@end

@implementation YSMarkBottomBar


-(instancetype)init{
    self = [super init];
    if(self){
        [self setFrame:CGRectMake(0,0, SCREENW, YSMarkBottomBarHeight)];
        [self setBackgroundColor:PUBLIC_BG];
        
        UIView *spliteView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 0.5)];
        [spliteView setBackgroundColor:HEXColor(@"#333333")];
        [self addSubview:spliteView];
        
        //全选按钮
        UIButton *statusBtn = [[UIButton alloc]initWithFrame:CGRectMake(YSPublicXInset, (YSMarkBottomBarHeight-21)/2, 21, 21)];
        [statusBtn setBackgroundImage:[UIImage imageNamed:@"btn_choose_normal"] forState:UIControlStateNormal];
        [statusBtn setBackgroundImage:[UIImage imageNamed:@"btn_choose_press"] forState:UIControlStateHighlighted];
        [statusBtn setBackgroundImage:[UIImage imageNamed:@"btn_choose_press"] forState:UIControlStateSelected];
        [statusBtn addTarget:self action:@selector(tapStatus:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:statusBtn];
        _statusBtn = statusBtn;
        
        //状态文字
        UILabel *statusLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.statusBtn.frame)+YSPublicXInset, CGRectGetMinY(self.statusBtn.frame), 100, 21)];
        [statusLabel setFont:SYS_FONT(16)];
        [statusLabel setTextColor:HEXColor(@"#333333")];
        [statusLabel setText:@"全选"];
        [self addSubview:statusLabel];
        _statusLabel = statusLabel;
        
        //删除按钮
        UIButton *deleteBtn =  [[UIButton alloc]initWithFrame:CGRectMake(SCREENW-60-YSPublicXInset, (YSMarkBottomBarHeight-35)/2, 60, 35)];
        [deleteBtn setBackgroundImage:[UIImage imageNamed:@"bg_btn_red"] forState:UIControlStateNormal];
        [deleteBtn setBackgroundImage:[UIImage imageNamed:@"bg_btn_red"] forState:UIControlStateHighlighted];
        [deleteBtn setBackgroundImage:[UIImage imageNamed:@"bg_btn_gray"] forState:UIControlStateDisabled];
        [deleteBtn addTarget:self action:@selector(tapDelete:) forControlEvents:UIControlEventTouchUpInside];
        [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [deleteBtn setTitleColor:PUBLIC_CARD_BG forState:UIControlStateNormal];
        [deleteBtn setTitleColor:HEXColor(@"#b9b9b9") forState:UIControlStateDisabled];
        
        [deleteBtn setCornerRadius:5 borderWidth:0.5 borderColor:HEXColor(@"#b9b9b9")];
        [deleteBtn setEnabled:NO];
        [self addSubview:deleteBtn];
        _deleteBtn = deleteBtn;
        
    }
    return self;
}

- (void)tapDelete:(UIButton *)sender {
    if(self.deleteOperation){
        self.deleteOperation();
    }
}

- (void)tapStatus:(UIButton *)sender {
   BOOL status = self.statusBtn.selected;
    
   if(!status){
        [self.deleteBtn setEnabled:YES];
    }else{
        [self.deleteBtn setEnabled:NO];
    }
    
   [self.statusBtn setSelected:!status];
   if(self.chooseOperation){
        self.chooseOperation();
   }
}


-(void)setHidden:(BOOL)hidden{
    [super setHidden:hidden];
    if(!hidden){
        [self.statusBtn setSelected:NO];
        [self.deleteBtn setEnabled:NO];
    }
}

@end
